let mongoose = require('./db')
let Schema = mongoose.Schema

function times() {
    var myDate = new Date(); //创建Date对象
    var Y = myDate.getFullYear(); //获取当前完整年份
    var M = myDate.getMonth() + 1; //获取当前月份
    var D = myDate.getDate(); //获取当前日1-31
    var H = myDate.getHours(); //获取当前小时
    var i = myDate.getMinutes(); //获取当前分钟
    var s = myDate.getSeconds(); //获取当前秒数
    // 月份不足10补0
    if (M < 10) {
        M = '0' + M;
    }// 日不足10补0
    if (D < 10) {
        D = '0' + D;
    }// 小时不足10补0
    if (H < 10) {
        H = '0' + H;
    }// 分钟不足10补0
    if (i < 10) {
        i = '0' + i;
    }// 秒数不足10补0
    if (s < 10) {
        s = '0' + s;
    }// 拼接日期分隔符根据自己的需要来修改
    return Y + '-' + M + '-' + D + ' ' + H + ':' + i + ':' + s; function times() {
        var myDate = new Date(); //创建Date对象
        var Y = myDate.getFullYear(); //获取当前完整年份
        var M = myDate.getMonth() + 1; //获取当前月份
        var D = myDate.getDate(); //获取当前日1-31
        var H = myDate.getHours(); //获取当前小时
        var i = myDate.getMinutes(); //获取当前分钟
        var s = myDate.getSeconds(); //获取当前秒数
        // 月份不足10补0
        if (M < 10) {
            M = '0' + M;
        }// 日不足10补0
        if (D < 10) {
            D = '0' + D;
        }// 小时不足10补0
        if (H < 10) {
            H = '0' + H;
        }// 分钟不足10补0
        if (i < 10) {
            i = '0' + i;
        }// 秒数不足10补0
        if (s < 10) {
            s = '0' + s;
        }// 拼接日期分隔符根据自己的需要来修改
        return Y + '-' + M + '-' + D + ' ' + H + ':' + i + ':' + s;
    }
}

//用户表
let Users = new Schema({
    username: String,  //账号昵称
    imgUrl: String,    //账号头像
    account: String,   //自定义的账号 号码
    phone: String,     //手机号
    password: String,  //密码
    ID_Number: String, //身份证号
    Ks: {              //科室表
        type: mongoose.Types.ObjectId,
        ref: 'Departments'
    }
})
let users_Model = mongoose.model('Users', Users, 'Users') //用户表


//科室表
let Departments = new Schema({
    title: String,      //科室名称
    top_id: String,     //科室上级名称
    introduce: String,  //科室介绍
})
let departments_Model = mongoose.model('Departments', Departments, 'Departments') //科室表

//我的当中的报告记录
//检查报告
let Inspection = new Schema({
    top_id: String,   //用户id
    title: String,    //检查报告名称
    code: String,     //报告单号
    time: {           //报告生成时间
        type: String,
        default: times()
    },
    examinationFinding: String,  //检查所见
    inspectionConclusion: String, //检查结论
})
let Inspection_Model = mongoose.model('Inspection', Inspection, 'Inspection') //检查表
//检验报告
let Inspection_two = new Schema({
    top_id: String,         //用户id
    title: String,          //检验报告名称
    code: String,           //报告单号
    startTime: { type: String, default: times() }, //送检日期
    endTime: String,        //报告日期
    hemoglobin: String,     //血红蛋白
    erythrocyte: String,    //红细胞
    platelet: String,       //血小板
    singleAbsolut: String,  //单核细胞绝对值
    iymphAbsolut: String,   //淋巴细胞绝对值
    barAbsolute: String,    //巴细胞百分比
    mcv: String,            //平均红细胞体积
})
let InspectionTwo_Model = mongoose.model('InspectionTwo', Inspection_two, 'InspectionTwo') //检验表

//预约挂号订单-已预约
let reserved = new Schema({
    top_id: String,     //上级用户的id
    username: String,   //就诊人
})

//健康课堂表
let HealthVideo = new Schema({
    user_id: {  //用户id
        type: mongoose.Types.ObjectId,
        ref: 'Users'
    },
    title: String, //视频标题
    imgUrl: String,  //封面图
    path: String,  //视频路径
    time: { type: String, default: times() },  //时间
    isTrue: Boolean,  //状态，是否可查看 
})


module.exports = {
    users_Model,        //用户表
    departments_Model,  //科室表
    Inspection_Model,   //检查报告表
    InspectionTwo_Model, //检验表
}